﻿using System;
using System.Configuration;



namespace GPSTrackingEmailManager
{   
    public class Manager
    {
             
        public static void Send(string To, string Subject, string Body, bool IsBodyHtml)
        {
            try
            {
                
                string From = ConfigurationManager.AppSettings["From"];
                string Host = ConfigurationManager.AppSettings["MailServer"];
                string UserName = ConfigurationManager.AppSettings["UserName"];
                string Password = ConfigurationManager.AppSettings["Password"];
                int    Port = Convert.ToInt32(ConfigurationManager.AppSettings["Port"]);
                
                System.Net.Mail.MailMessage Mail = new System.Net.Mail.MailMessage();
                Mail.To.Add(To);
                Mail.From = new System.Net.Mail.MailAddress(From);
                Mail.Subject = Subject;
                Mail.Body = Body;
                Mail.IsBodyHtml = IsBodyHtml;

                System.Net.Mail.SmtpClient Stmp = new System.Net.Mail.SmtpClient();
                Stmp.Host = Host;
                System.Net.NetworkCredential Credential = new System.Net.NetworkCredential();
                Credential.UserName = UserName;
                Credential.Password = Password;
                Stmp.UseDefaultCredentials = false;
                Stmp.Credentials = Credential;
                Stmp.Port = Port;

                Stmp.Send(Mail);
            }
            catch (System.Net.Mail.SmtpException ex)
            {
                throw ex;
            }

        }
    }
}
